﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Soundteller.Audio.Model;
using Soundteller.Audio.Model.Interfaces;
using Soundteller.Audio.Repositories;
using Soundteller.Audio.Repositories.Interfaces;
using Soundteller.Common.Tests;

namespace Soundteller.Audio.Tests.Unit.Repositories.SoundBufferRepositorySpecifications
{
    public abstract class WhenPop : TestBase
    {
        protected ISoundBufferRepository SoundBufferRepository { get; private set; }
        protected Mock<IMemoryContext> Context { get; private set; }
        protected Sound Result { get; private set; }

        protected override void Arrange()
        {
            Context = new Mock<IMemoryContext>();
            Context.Setup(c => c.SoundBuffer).Returns(new Stack<Sound>());

            SoundBufferRepository = new SoundBufferRepository(Context.Object);
        }

        protected override void Act()
        {
            Result = SoundBufferRepository.Pop();
        }
    }

    [TestClass]
    public class WhenPopGivenEmptyBuffer : WhenPop
    {
        protected override void Act()
        {
            ExpectException(() => base.Act());
        }

        [TestMethod]
        public void ThenAnInvalidOperationExceptionShouldBeThrown()
        {
            Exception.VerifyInvalidOperationException("Stack empty.");
        }
    }

    [TestClass]
    public class WhenPopGivenOneItemInBuffer : WhenPop
    {
        protected override void Arrange()
        {
            base.Arrange();

            var buffer = new Stack<Sound>();
            buffer.Push(new Sound());
            Context.Setup(c => c.SoundBuffer).Returns(buffer);
        }

        [TestMethod]
        public void ThenResultShouldNotBeNull()
        {
            Assert.IsNotNull(Result);
        }
    }
}
